import request from '../../request/index'
const state = {
    User: [],
    Edit: {},
    sxList: [],
    Search: []
}
const getters = {

}
const mutations = {
    setData(state, data) {
        state.User = data
    },
    setUser(state, data) {
        console.log(data);
        request({
            url: '/setUser',
            method: 'GET',
            params: data
        }).then(res => {
            console.log(res);
        })
    },
    delUser(state, index) {
        request({
            url: '/delUser',
            method: 'GET',
            params: { index }
        }).then(res => {
            console.log(res);
        })
    },
    Edit(state, data) {
        state.Edit = data
    },
    Role(state, data) {
        if (data === '管理员') {
            state.sxList = state.User.filter(item => {
                console.log(item.state);
                return item.state === '1'
            })
        } else if (data === '店员') {
            state.sxList = state.User.filter(item => {
                return item.state === '2'
            })
        } else {
            state.sxList = state.User
        }
        console.log(state.sxList);
    },
    Search(state, val) {
        state.Search = state.User.filter(item => {
            return item.user.indexOf(val) !== -1
        })
    },
    editOk(state, item) {
        request({
            url: '/editOk',
            method: 'GET',
            params: item
        })
    }
}
const actions = {
    async getNavList(store) {
        let res = await request({
            url: '/OneUser',
            method: 'GET',
            params: {}
        }).then(res => {
            store.commit('setData', res)
            return res
        })
        return res
    }
}
export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}